/*  -*- mode: c++; coding: utf-8; c-file-style: "stroustrup"; -*-

    Copyright 2008 Asier Aguirre <asier.aguirre@gmail.com>
    This file is part of Intromit.

    Intromit is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Intromit is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Intromit.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef ELF_HH
#define ELF_HH
//! \addtogroup intromit_core
//@{

#include "util.hh"

// DEFINITIONS
#define ELF_SEPARATOR_CHARACTER   ';'  // used by get symbols to separate mangled and demangled names

// DECLARATIONS
class string_index;
struct bfd;

// CLASSES

//! ELF files browser and data extractor
class elf
{
    // ** CTOR/INIT VARIABLES **
    // obsolete variables
    char *elf_mem;
    int n_elf_mem;

    // ** STATUS VARIABLES **
    char *elf_filename;

    // ** PRIVATE FUNCTIONS **
    void free_elf();
    bool open_elf();
    static void add_symbol(bfd *elf_file, string_index *symtab, char *mangled, int demangle);

    // internal
    void ctor();
    void dtor();

public:
    elf();
    ~elf();
    bool init();

    //! Extract symbol names from ELF file
    //! \param file_name the name of the ELF file
    //! \param symtab string indexer class where symbols will be stored
    //! \param demangle set to 1 to get demangled symbols
    //! \return false on error
    static bool get_symbols(char *file_name, string_index *symtab, int demangle=0);

    // obsolete functions (loads elf into memory)
    bool set_elf_file(char *filename);

    // obsolete, used in conjunction with set_elf_file
    bool dump();
};

//@}
#endif
